<template>
    <div class="app-container">
      <!-- 输入表单 -->
      <el-form label-width="120px">
        <el-form-item label="收货人">
          <el-input v-model="order.consigneeName" />
        </el-form-item>
        
        <el-form-item label="手机号">
            <el-input v-model="order.telephone" />
        </el-form-item>
        <el-form-item label="订单状态">
            <el-select v-model="order.orderStatusId" clearable placeholder="请选择">
              <el-option
                v-for="item in orderStatusList"
                :key="item.id"
                :label="item.orderStatus"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        <el-form-item label="收货地址">
            <el-input v-model="order.address" />
        </el-form-item>
  
        <el-form-item>
          <el-button type="primary" @click="saveOrUpdate()">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </template>
  
  
  <script>
  import orderApi from "@/api/order/order";
  export default {
      data() {
          return {
              order:{
              },
              orderStatusList: [],
          }
      },
      created() {
        if(this.$route.params.id){
          const id = this.$route.params.id;
          this.fetchDataById(id)
        }
      },
      methods: {
        fetchDataById(id){
            orderApi.getOrderById(id)
            .then(response => {
                this.order = response.data
            })
            orderApi.getOrderStatusList()
            .then(response => {
                this.orderStatusList = response.data
            })
        },
        // //添加
        // save(){
        //   goods.saveGoods(this.goods)
        //   .then((response) => {
        //       this.$message({
        //           type: 'success',
        //           message: '添加成功!'
        //       });
        //       //跳转列表页面
        //       this.$router.push({path:'/goods/list'})
        //   })
        // },
        //修改
        update(){
          orderApi.updateOrder(this.order)
          .then((response) => {
              this.$message({
                  type: 'success',
                  message: '修改成功!'
              });
              //跳转列表页面
              this.$router.push({path:'/order/list'})
          })
        },
        saveOrUpdate(){
        //   if(this.order.id){
            this.update()
        //   }else{
            // this.save()
        //   }
        },
      },
      
  }
  </script>

  <style>
  </style>